package com.bodacn.keypoint.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bodacn.keypoint.R;
import com.bodacn.keypoint.bean.TaskBottomBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by KangJunjie on 2020/6/18.
 */
public class TaskBottomAdapter extends BaseAdapter {
    private Context context;
    private List<TaskBottomBean> dataBeans;
    private OrderDetialOn orderDetialOn;

    public TaskBottomAdapter(Context context, List<TaskBottomBean> beanList, OrderDetialOn orderDetialOn) {
        this.context = context;
        this.dataBeans = beanList;
        this.orderDetialOn = orderDetialOn;
    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return dataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_task_bottom_head, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (dataBeans.size() > 0) {
            TaskBottomBean taskTopBean = dataBeans.get(position);
            if (!TextUtils.isEmpty(taskTopBean.getCallTime())) {
                viewHolder.tvHjsj.setText(taskTopBean.getCallTime());
            } else {
                viewHolder.tvHjsj.setText("");
            }
            if (!TextUtils.isEmpty(taskTopBean.getCallStartPlace())) {
                viewHolder.tvHjqd.setText(taskTopBean.getCallStartPlace());
            } else {
                viewHolder.tvHjqd.setText("");
            }
            if (!TextUtils.isEmpty(taskTopBean.getCallEndPlace())) {
                viewHolder.tvHjzd.setText(taskTopBean.getCallEndPlace());
            } else {
                viewHolder.tvHjzd.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getPlaceNo())) {
                viewHolder.tvHjh.setText(taskTopBean.getPlaceNo());
            } else {
                viewHolder.tvHjh.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getTaskType())) {
                viewHolder.tvRwlx.setText(taskTopBean.getTaskType());
            } else {
                viewHolder.tvRwlx.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getCurrentState())) {
                viewHolder.tvDqzt.setText(taskTopBean.getCurrentState());
            } else {
                viewHolder.tvDqzt.setText("");
            }

            if (!TextUtils.isEmpty(taskTopBean.getMotionAnalysis())) {
                viewHolder.tcDzfx.setText(taskTopBean.getMotionAnalysis());
            } else {
                viewHolder.tcDzfx.setText("");
            }

            viewHolder.tvJy.setText("取消任务");
            viewHolder.tvJy.setBackgroundColor(context.getResources().getColor(R.color.red));
            viewHolder.tvJy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    orderDetialOn.Onclick(position);
                }
            });

        }
        return convertView;
    }

    public interface OrderDetialOn {
        void Onclick(int position);
    }


    class ViewHolder {
        @BindView(R.id.tv_hjsj)
        TextView tvHjsj;
        @BindView(R.id.tv_hjqd)
        TextView tvHjqd;
        @BindView(R.id.tv_hjzd)
        TextView tvHjzd;
        @BindView(R.id.tv_hjh)
        TextView tvHjh;
        @BindView(R.id.tv_rwlx)
        TextView tvRwlx;
        @BindView(R.id.tv_dqzt)
        TextView tvDqzt;
        @BindView(R.id.tc_dzfx)
        TextView tcDzfx;
        @BindView(R.id.tv_jy)
        TextView tvJy;
        @BindView(R.id.ll)
        LinearLayout ll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
